
T.Marker = T.Layer.extend({

	options: {
		pane: 'markerPane',
		icon: '/tiny/images/marker-icon.png',
        interactive: true,
        zIndexOffset: 0,
        anchor: [ 0.5, 41 ],
        anchorXUnits : 'fraction',
        anchorYUnits : 'pixels',    
        opacity: 1
	},

	initialize: function (latlng, options) {
		T.setOptions(this, options);
		this._coord = latlng;
		this._latlng = T.Util.transform4326to3857(latlng);
	},

	onAdd: function (map) {
	    this._initIcon();
	    this._loadSource();
	    this._loadLayer();
        
        map.tinyMap.addLayer(this.layer);
	},
	
	_loadSource: function(){
        this.source = new ol.source.Vector({
            features: [this.iconFeature]
        });
    },
    
    _loadLayer: function(){
        this.layer = new ol.layer.Vector({
            source: this.source
        });
    },
    
    _initIcon: function(){
        this.iconFeature = new ol.Feature({
            geometry : new ol.geom.Point(this._latlng)
        });
        
        this.iconStyle = new ol.style.Style({
            image : new ol.style.Icon({
                anchor : this.options.anchor,
                anchorXUnits : this.options.anchorXUnits,
                anchorYUnits : this.options.anchorYUnits,
                opacity : this.options.opacity,
                src : this.options.icon
            })
        });
        
        this.iconFeature.setStyle(this.iconStyle);
    }
});

T.marker = function (latlng, options) {
	return new T.Marker(latlng, options);
};
